package main

/*
二个日期段的日期列表
*/
import (
	"log"
	"time"
)

func main() {
	var (
		err    error
		start  string
		end    string
		start1 time.Time
		end1   time.Time
		//dates []string
	)
	start = "2017-04-08 12:33:21" //日期字符串
	end = "2017-06-01 12:32:21"   //日期字符串
	log.Println("start:", start, "\t end:", end)
	start1, err = time.Parse("2006-01-02 15:04:05", start) //转成time，必须与日期字符串里字符一致
	checkErr(err)
	end1, err = time.Parse("2006-01-02 15:04:05", end) //转成time，必须与日期字符串里字符一致
	checkErr(err)
	log.Println("start1:", start1, "\t end1:", end1)
	log.Println("TIME转成日期字符串1：", start1.Format("2006-01-02 15:04:05"))
	log.Println("TIME转成日期字符串2：", end1.Format("2006-01-02"))

	addhour, _ := time.ParseDuration("+24h") //定义一个增加24小时的结构
	for start1.Unix() <= end1.Unix() {
		log.Println("自增操作：", start1.Format("2006-01-02"))
		start1 = start1.Add(addhour) //start1日期自增加1天
	}
}

func checkErr(err error) {
	if err != nil {
		log.Println("转换日期字符串到time结构体时出错,err:", err)
	}
}
